package com.example.zzl.view.fragment.SearchFragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.example.zzl.R;
import com.example.zzl.adapter.SearchFragment.SearchFrgmentAdapter;
import com.example.zzl.databinding.FragmentSearchBinding;
import com.example.zzl.model.bean.SearchFragment.LoadData;
import com.example.zzl.view.BaseFragment;
import com.example.zzl.view.activity.MainActivity;
import com.example.zzl.view.activity.SearchActivity.SearchActivity;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 */
public class SearchFragment extends BaseFragment implements View.OnClickListener{

    private TextView tv;
    private TabLayout tab;
    private ViewPager vp;
    private FragmentSearchBinding fsb;
    private SearchFrgmentAdapter adapter;
    private ArrayList<Fragment> fragments;
    public static SearchFragment newInstance(String data) {
        Bundle args = new Bundle();
        args.putString("data", data);
        SearchFragment fragment = new SearchFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public SearchFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        fsb = DataBindingUtil.inflate(inflater,R.layout.fragment_search,container,false);
        tv = fsb.etSearch;
        tab = fsb.tabSearch;
        vp = fsb.vp;
        tab.setTabTextColors(Color.parseColor("#686868"),Color.RED);
        tab.setSelectedTabIndicatorHeight(4);
        tab.setSelectedTabIndicatorColor(Color.RED);
        tab.setTabMode(TabLayout.MODE_SCROLLABLE);
        tab.setTabGravity(TabLayout.GRAVITY_CENTER);
        fragments = new ArrayList<>();
        fragments.add(ClassifyFragment.getInstance());
        fragments.add(BrandFragment.getInstance());
        adapter = new SearchFrgmentAdapter(getChildFragmentManager(),fragments,getActivity().getResources().getStringArray(R.array.search_title));
        vp.setAdapter(adapter);
        tab.setupWithViewPager(vp,true);
        fsb.setClick(this);
        return fsb.getRoot();


    }


    @Override
    public void onClick(View view) {
        startActivityForResult(new Intent(getActivity(), SearchActivity.class),200);
    }
}
